#include "contourdetector.h"
#include "opencv2/objdetect/objdetect.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
#include <stdio.h>

using namespace std;
using namespace cv;

ContourDetector::ContourDetector()
{
}


void ContourDetector::detect ( Mat frame )
{
    Mat src_gray;

    baseImage = frame;

    cvtColor( frame, src_gray, CV_BGR2GRAY );
    blur( src_gray, src_gray, Size(3,3) );

    vector<vector<Point> > contours;
    vector<Vec4i> hierarchy;

    /// Detect edges using canny
    Canny( src_gray, intermediateImage, thresh, thresh*2, 3 );
    /// Find contours
    findContours( intermediateImage, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0) );

    /// Draw contours
    endImage = baseImage.clone ( );
    for( int i = 0; i< contours.size(); i++ )
    {
       Scalar color = Scalar( 0, 255, 0 );
       drawContours( endImage, contours, i, color, 2, 8, hierarchy, 0, Point() );
    }

}
